import 'package:duqin/components/root_head.dart';
import 'package:duqin/http/http.dart';
import 'package:duqin/pages/sub_pages/song_page.dart';
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  late TabController _tabController; //需要定义一个Controller
  List tabs = ["歌曲", "推荐", "歌手", "小视频", "文章", "视频"];

  List<Widget> tabViews = [
    SongPage(),
    Text('11111'),
    Text('11111'),
    Text('11111'),
    Text('11111'),
    Text('11111'),
  ];

  @override
  void initState() {
    super.initState();
    // 创建Controller
    _tabController =
        TabController(initialIndex: 1, length: tabs.length, vsync: this);

    // getList();
  }

  // Future getList() async {
  //   final res = await Http.get('/car/?type=brand&from=0&pagesize=300');
  //   print(res);
  // }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: RootHead(),
        bottom: TabBar(
            isScrollable: true,
            //生成Tab菜单
            controller: _tabController,
            tabs: tabs.map((e) => Tab(text: e)).toList()),
      ),
      body: TabBarView(
        controller: _tabController,
        children: tabViews,
      ),
    );
  }
}
